using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Opc.Ua;

namespace OpcuaClient.Model
{
    /// <summary>
    /// 数据采集点位
    /// </summary>
    public class Collection
    {
        /// <summary>
        /// 点位键
        /// </summary>
        public string Key { get; set; }
        /// <summary>
        /// 点位名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 点位地址
        /// </summary>
        public string Address { get; set; }
        /// <summary>
        /// 数据类型
        /// </summary>
        public string DataType { get; set; }
        /// <summary>
        /// 读取类型，Read/Wright/Subscribe
        /// </summary>
        public string ReadType { get; set; }
        /// <summary>
        /// 数据值类型
        /// </summary>
        public string ValueType { get; set; }
        /// <summary>
        /// 写入值类型；WaferId
        /// </summary>
        public string WriteType { get; set; }
        /// <summary>
        /// 写入值前缀
        /// </summary>
        public string Prefix { get; set; }
        /// <summary>
        /// 刷新频次（当有前提条件时，当前提条件满足后再按此频次采集）
        /// </summary>
        public int Frequency { get; set; }
        /// <summary>
        /// 采集值
        /// </summary>
        public object Value { get; set; }
        /// <summary>
        /// 前提条件（当此点位有新值时采集）
        /// </summary>
        public string Precondition { get; set; }
        /// <summary>
        /// 消息主题
        /// </summary>
        public string Topic { get; set; }
        /// <summary>
        /// 采集状态
        /// </summary>
        public bool Status { get; set; }
        /// <summary>
        /// 采集时间
        /// </summary>
        public DateTime CollectTime { get; set; }
        /// <summary>
        /// 采集点位
        /// </summary>
        private NodeId node { get; set; }
        public NodeId Node
        {
            get { return node; }
            set
            {
                if (value.Identifier.ToString() != Name && !string.IsNullOrWhiteSpace(Address))
                {
                    node = NodeId.Parse(Address);
                }
                else
                {
                    node = value;
                }
            }
        }
    }
}
